﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Pacifico.DataAccess.INFORME_ACCIDENTE_VEHICULAR>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Editar Informe Vehicular
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>Editar Informe Vehicular</h2>

<% using (Html.BeginForm()) { %>
    <%: Html.ValidationSummary(true) %>

    <%: Html.Hidden("Co_InformeAccidenteVehicular", ViewData["Co_InformeAccidenteVehicular"]) %>
    <%: Html.Hidden("Co_Siniestro", ViewData["Co_Siniestro"]) %>
    
    <div class="form-actions">
    <h4>
     <font color="red"  id="errorMessage">
                <p><%: ViewData["Error"] %></p>
                <p><%: Html.ValidationMessageFor(model => model.Tx_Direccion) %></p>
                <p><%: Html.ValidationMessageFor(model => model.Co_Distrito) %></p>
                <p><%: Html.ValidationMessageFor(model => model.Co_Siniestro) %></p>
                <p><%: Html.ValidationMessageFor(model => model.Tx_DanosProducidos) %></p>                
         
            </font>
        </h4>
<table width="100%">        
    <tr>
        <td>&nbsp;</td>
        <td><label for="Co_Prestadora">Siniestro</label></td> 
        <td><label>:</label></td>
        <td>
              <%= ViewData["Nu_Siniestro"] %>
        </td>
        <td>&nbsp;</td>
        <td><label>Departamento</label></td>
            <td><label>:</label></td>
            <td><%:Html.DropDownList("dsDepartamentoList", (SelectList)ViewData["dsDepartamento"], "---------Seleccione---------")%></td>
        <td>&nbsp;</td>
   </tr>
    <tr>            
            <td>&nbsp;</td>
           
        <td><label>Provincia</label></td>
        <td><label>:</label></td>
        <td><%:Html.DropDownList("dsProvinciaList", (SelectList)ViewData["dsProvincia"], "---------Seleccione---------")%></td>
        <td>&nbsp;</td>
        <td><label for="Co_Distrito">Distrito</label></td>
        <td><label>:</label></td>
        <td><%:Html.DropDownList("dsDistritoList", (SelectList)ViewData["dsDistrito"], "---------Seleccione---------")%></td>
        <td>&nbsp;</td>            
    </tr>

    <tr>
        <td>&nbsp;</td>
        <td><label for="Co_Prestadora">Direcci&oacute;n</label></td>
        <td><label>:</label></td>
        <td>
            <%: Html.EditorFor(model => model.Tx_Direccion) %>            
        </td>
        <td>&nbsp;</td>
        <td><label>Da&ntilde;os Producidos</label></td>
        <td><label>:</label></td>
        <td>
            <%: Html.EditorFor(model => model.Tx_DanosProducidos) %>            
        </td>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td style="height: 23px"></td>
        <td style="height: 23px">Fecha y hora</td>
        <td style="height: 23px">:</td>        
        <td><%: Html.TextBox("Fe_InformeAccidentVehicular", String.Format("{0:yyyy-MM-dd h:mm}", Model.Fe_InformeAccidentVehicular), new { @readonly = "readonly" } ) %></td>
        <td style="height: 23px"></td>
        <td style="height: 23px"></td>
        <td style="height: 23px"></td>
        <td style="height: 23px"></td>
        <td style="height: 23px"></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td colspan="7" align="center">
            <input type="button" value="Grabar Datos" class="btn" onclick="javascript: validarForm()" />
             &nbsp;
            <%: Html.ActionLink("Cancelar", "Index", "InformeAccidenteVehicular", routeValues: null, htmlAttributes: new {@class="btn", onclick = "return confirm('¿Desea salir de Editar Informe de Accidente Vehicular?')" })%>

         </td>
       <td>&nbsp;</td>
     </tr>    
</table>

    </div>

<% } %>

<div>
    <%: Html.ActionLink("Back to List", "Index") %>
</div>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
    <link href="/Content/bootstrap-datetimepicker.css" rel="stylesheet">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
    <%: Scripts.Render("~/bundles/jqueryval") %>
    <script src="/Scripts/bootstrap-datetimepicker.min.js"></script>
    <script>
    
            $(document).ready(function () {
                $("#Fe_InformeAccidentVehicular").datetimepicker({ format: 'yyyy-mm-dd hh:ii', forceParse: true });
                $("#dsDepartamentoList").change(function () {
                    llenarProvincias($("#dsDepartamentoList").val());
                });
                $("#dsProvinciaList").change(function () {
                    llenarDistritos($("#dsProvinciaList").val(), $("#dsDepartamentoList").val());
                });
            });
    
        function validarForm() {
            $("#errorMessage").text("");
            
            var dsDepartamentoList = $("#dsDepartamentoList").val();
            var dsProvinciaList = $("#dsProvinciaList").val();
            var dsDistritoList = $("#dsDistritoList").val();
            var Tx_Direccion = $("#Tx_Direccion").val();
            var Tx_DanosProducidos = $("#Tx_DanosProducidos").val();
            var Fe_InformeAccidentVehicular = $("#Fe_InformeAccidentVehicular").val();


            if (dsDepartamentoList != ''
                && dsProvinciaList != ''
                && dsDistritoList != ''
                && Tx_Direccion != ''
                && Tx_DanosProducidos != ''
                && Fe_InformeAccidentVehicular != ''
                ) {
                $("form").submit();
                return true;
            } else {
                $("#errorMessage").text("Ingrese todos los datos");
            }

            return false;
        }

        function llenarProvincias(value) {
            var selectedValue = value;
            $.ajax({
                url: '<%:Url.Action("GetProvincia", "Prestadora")%>',
                type: 'POST',
                data: { "selectedValue": selectedValue },
                dataType: 'json',
                success: function (response) {
                    var items = "";
                    var items2 = "<option value=\"\">---------Seleccione---------</option>";
                    items += "<option value=\"\">---------Seleccione---------</option>";
                    $.each(response.provList, function (i, item) {
                        items += "<option value=\"" + item + "\">" + item + "</option>";
                    });
                    $("#dsProvinciaList").html(items);
                    $("#dsDistritoList").html(items2);
                },
                error: function (error) {
                    aler("error");
                }
            });
        }


        function llenarDistritos(pro, dep) {
            var selectedProv = pro;
            var selectedDept = dep;
            $.ajax({
                url: '<%:Url.Action("GetDistrito", "Prestadora")%>',
                type: 'POST',
                data: { "selectedProv": selectedProv, "selectedDept": selectedDept },
                dataType: 'json',
                success: function (response) {
                    var items = "";
                    items += "<option value=\"\">---------Seleccione---------</option>";
                    $.each(response.distList, function (i, item) {
                        items += "<option value=\"" + item + "\">" + item + "</option>";
                    });
                    $("#dsDistritoList").html(items);
                },
                error: function (error) {
                    aler("error");
                }
            });
        }

    </script>
</asp:Content>
